package com.nbsaas.boot.project.controller;

import com.nbsaas.boot.project.api.apis.ProjectTravelApi;
import com.nbsaas.boot.project.api.domain.request.ProjectTravelRequest;
import com.nbsaas.boot.project.api.domain.request.ProjectTravelSearch;
import com.nbsaas.boot.project.api.domain.response.ProjectTravelResponse;
import com.nbsaas.boot.project.api.domain.simple.ProjectTravelSimple;
import com.nbsaas.boot.rest.annotations.*;
import com.nbsaas.boot.rest.response.ListResponse;
import com.nbsaas.boot.rest.response.PageResponse;
import com.nbsaas.boot.rest.response.ResponseObject;
import jakarta.annotation.Resource;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 出差控制器
 */
@RequiresAuthentication
@RestController
@RequestMapping("/projectTravel")
public class ProjectTravelController {


    @Resource
    private ProjectTravelApi projectTravelApi;

    /**
     * 搜索数据
     *
     * @param request
     * @return
     */
    @SearchData
    @RequiresPermissions("projectTravel:search")
    @PostMapping("/search")
    public PageResponse<ProjectTravelSimple> search(@RequestBody ProjectTravelSearch request) {
        return projectTravelApi.search(request);
    }

    /**
     * 列表数据
     *
     * @param request
     * @return
     */
    @SearchData
    @RequiresPermissions("projectTravel:list")
    @PostMapping("/list")
    public ListResponse<ProjectTravelSimple> list(@RequestBody ProjectTravelSearch request) {
        return projectTravelApi.list(request);
    }

    /**
     * 添加数据
     *
     * @param request
     * @return
     */
    @RequiresPermissions("projectTravel:create")
    @CreateData
    @PostMapping("/create")
    public ResponseObject<ProjectTravelResponse> create(@RequestBody @Validated(AddOperator.class) ProjectTravelRequest request) {
        return projectTravelApi.create(request);
    }

    /**
     * 修改数据
     *
     * @param request
     * @return
     */
    @RequiresPermissions("projectTravel:update")
    @UpdateData
    @PostMapping("/update")
    public ResponseObject<ProjectTravelResponse> update(@RequestBody @Validated(UpdateOperator.class) ProjectTravelRequest request) {
        return projectTravelApi.update(request);
    }

    /**
     * 删除数据
     *
     * @param request
     * @return
     */
    @SearchData
    @RequiresPermissions("projectTravel:delete")
    @PostMapping("/delete")
    public ResponseObject<?> delete(@RequestBody @Validated(DeleteOperator.class) ProjectTravelRequest request) {
        return projectTravelApi.delete(request);
    }

    /**
     * 查看数据
     *
     * @param request
     * @return
     */
    @SearchData
    @RequiresPermissions("projectTravel:view")
    @PostMapping("/view")
    public ResponseObject<ProjectTravelResponse> view(@RequestBody @Validated(ViewOperator.class) ProjectTravelRequest request) {
        return projectTravelApi.view(request);
    }
}